import unittest

import ddt

from common.base import get_driver
from page.index_page import IndexPage
from page.register_page import RegisterPage
from common.data_operation import DataOperation

data = DataOperation('register_info.csv')
register_data = data.get_data_to_dict()


@ddt.ddt
class RegisterTestCase(unittest.TestCase):
    register_data = register_data

    @classmethod
    def setUpClass(cls) -> None:
        # 创建浏览器对象，打开浏览器
        driver = get_driver()
        # 请求测试网址
        driver.get(RegisterPage.register_url)
        cls.register = RegisterPage(driver)
        cls.index = IndexPage(driver)

    @ddt.data(*register_data)
    def test_register(self, register_info):
        # TODO 操作流程'
        expect_username = register_info['username']
        # 输入用户名
        self.register.input_username(expect_username)
        # 输入邮箱
        self.register.input_email(str(register_info['email']))
        # 输入密码
        self.register.input_password(str(register_info['password']))
        # 再次输入密码
        self.register.input_conform_password(str(register_info['conform_password']))
        # 输入手机号码
        self.register.input_phone(str(register_info['phone']))

        # self.login.input_remember()
        # 点击立即注册
        self.register.input_submit()


        # TODO 断言，左上角的用户名和注册的用户名一致
        # 预期结果 和 实际结果的比对
        # 定位实际结果
        actual_username = self.index.font_username_text()
        self.assertEqual(expect_username, actual_username, msg=register_info['title'])

    def tearDown(self) -> None:
        self.index.a_logout()
        self.index.a_register()

    @classmethod
    def tearDownClass(cls) -> None:
        cls.register.quit(3)


if __name__ == '__main__':
    unittest.main(verbosity=2)
